public class ThreadDemo05 {
    public static void main(String[] args) throws InterruptedException {
        MyThread02 myThread02 = new MyThread02();
        myThread02.setDaemon(true);// 设置成守护线程,最为后台线程
        myThread02.start();

        for (int i = 0; i < 10; i++) {
            Thread.sleep(1000);
            System.out.println(Thread.currentThread().getName() + i);
        }
    }
}


class MyThread02 extends Thread {
    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(3 * 1000);
                System.out.println("备份一下数据");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
